#include "DungeonsItem.h"
#include "../../model/static/StaticDungeons.h"
#include "../../model/proxy/DungeonsProxy.h"

DungeonsItem::DungeonsItem(void)
	:mName(NULL), mBg(NULL), mGoBtn(NULL)
{
	
}

DungeonsItem::~DungeonsItem(void)
{
}

cocos2d::SEL_MenuHandler DungeonsItem::onResolveCCBCCMenuItemSelector( cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onBgClick", DungeonsItem::onBgClick);
	return NULL;
}

cocos2d::extension::SEL_CCControlHandler DungeonsItem::onResolveCCBCCControlSelector( cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onGoBtnClick", DungeonsItem::onGoBtnClick);
	return NULL;
}

bool DungeonsItem::onAssignCCBMemberVariable( cocos2d::CCObject * pTarget, cocos2d::CCString * pMemberVariableName, cocos2d::CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName", CCLabelTTF *, this->mName);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBg", CCSprite *, this->mBg);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mGoBtn", CCControlButton *, this->mGoBtn);
	return true;
}


void DungeonsItem::onNodeLoaded( cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader )
{
	
}


void DungeonsItem::onEnter()
{
	CCNode::onEnter();
	//refresh();
}

void DungeonsItem::onExit()
{
	CCNode::onExit();
}

void DungeonsItem::refresh()
{
	FloorStatic* floorInfo = DungeonsProxy::getSingletonPtr()->getCurFloorStatic();
	int maxFloorID = DungeonsProxy::getSingletonPtr()->getMaxFloorID();
	
	if(floorID>maxFloorID)
	{
		mName->setString("");
		mBg->initWithFile("sprite/bg_15.png");
		this->removeChild(mGoBtn, true);
	}
	else
	{
		mName->setString(floorInfo->name);
		mBg->initWithFile("sprite/bg_14.png");
	}
}

bool DungeonsItem::init()
{
	return true;
}

void DungeonsItem::onBgClick( cocos2d::CCObject * pSender )
{
	
}

void DungeonsItem::onGoBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	DungeonsProxy::getSingletonPtr()->setCurFloor(dungeonsID, floorID);
	Framework::getSingletonPtr()->changeState("DungeonsScene");
}
